{{template "main" .}}
{{define "content"}}
<div class="container">
	<div class="row">
		<h1 class="col-md-6">文章列表</h1>
		<h4 class="col-md-offset-3 col-md-3 text-center">
			<div class="well well-sm">
				<span class="label label-default">帐号名：{{.adminName}}</span>&nbsp;&nbsp;
				<a href="/admin/handle-sign-out" class="btn btn-xs btn-danger">注销</a>
			</div>
		</h4>
	</div>
	<div class="row">
		<div class="col-md-1">
			<a href="/admin/upsert-article" class="btn btn-default">添加文章</a>
		</div>
	</div>
	<hr />
	<table class="table table-bordered table-striped table-hover">
		<thead>
			<th>ID</th>
			<th>标题</th>
			<th>创建时间</th>
			<th>修改时间</th>
			<th>操作</th>
		</thead>
		<tbody>
			{{range .resArr}}
			<tr>
				<td>{{.id}}</td>
				<td>{{.title}}</td>
				<td>{{.ctime}}</td>
				<td>{{.mtime}}</td>
				<td>
					<a href="/admin/show-article?id={{.id}}" class="btn btn-info btn-xs">查看</a>
					<a href="/admin/upsert-article?id={{.id}}" class="btn btn-warning btn-xs">修改</a>
					<button type="button" class="btn btn-danger btn-xs" onclick="delArticle({{.id}})">删除</button>
				</td>
			</tr>
			{{end}}
		</tbody>
	</table>
	<nav>
		<ul class="pagination">
			<li class="disabled"><a href="javascript:void(0)">共 {{.pageCount}} 页， 第 {{.page}} 页</a></li>
	    	<li><a href="/admin/manage?page=1"><span aria-hidden="true">First</span></a></li>
	    	<li><a href="/admin/manage?page={{.prePage}}"><span aria-hidden="true">&laquo;</span></a></li>
	    	{{range .preArr}}
	    	<li><a href="/admin/manage?page={{.}}">{{.}}</a></li>
	    	{{end}}
			<li class="active"><a href="/admin/manage?page={{.page}}"> {{.page}} <span class="sr-only">(current)</span></a></li>
	    	{{range .nextArr}}
	    	<li><a href="/admin/manage?page={{.}}">{{.}}</a></li>
	    	{{end}}
		    <li><a href="/admin/manage?page={{.nextPage}}"><span aria-hidden="true">&raquo;</span></a></li>
		    <li><a href="/admin/manage?page={{.pageCount}}"><span aria-hidden="true">Last</span></a></li>
		</ul>
	</nav>	
</div>

<script>
/**
 * 根据id删除文章
 */
function delArticle(id) {
	if (!confirm("您确定要删除这篇文章？")) {
		return
	}
	$.post("/admin/del-article", {"id": id}, function(data) {
		if (data.status != "200") {
			return alert(data.msg)
		}
		location = "/admin/mange?t=" + new Date().getTime()
	}, "json")
}
</script>

{{end}}